package com.huilian.iotbox.mqtt.server.base.handler;

import com.huilian.iotbox.data.common.RedisKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

/**
 * RemoteWriteDeviceNoHandler
 * 31.1 远程烧号回复（支付盒子to服务器）
 *
 * @Author zhang
 * @Date 2023-10-24
 */
@Slf4j
@Service("messageHandleServiceF1")
public class RemoteWriteDeviceNoHandler implements MessageHandlerStrategy{


    @Autowired
    private RedisTemplate<String, Serializable> redisCacheTemplate;
    @Override
    public void process(String content, String deviceNo, String productKey, Integer serviceProviderCode) throws Exception {
        log.info("进入 烧号回复结果" + deviceNo);
        //AA0401310135DD
        final String status = content.substring(8, 10);
        if ("00".equals(status)){
            log.error("烧号结果: 失败");
        } else if ("01".equals(status)){
            log.info("烧号结果: 成功");
            redisCacheTemplate.opsForValue().set(RedisKey.REMOTE_WRITE_DEVICENO +deviceNo,status,4, TimeUnit.SECONDS);
        }
    }

}
